package com.yj.daily.designpatterns.prototype;

import lombok.Data;

@Data
public class Student implements Cloneable {
    private int id;
    private String name;
    private int age;


    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student student = new Student();
        student.id = this.id;
        student.name = this.name;
        student.age = this.age;
        return student;
    }

    public Student copy(){
        Student student = new Student();
        student.id = this.id;
        student.name = this.name;
        student.age = this.age;
        return student;
    }



    public static void main(String[] args) throws CloneNotSupportedException {
        Student student = new Student();
        student.setId(1);
        student.setAge(20);
        student.setName("yj");
        System.out.println("student1:"+student);
        Student cloneStudent = (Student) student.clone();
        System.out.println("student-clone:"+cloneStudent);

        Student copyStudent = student.copy();
        System.out.println("copyStudent:"+copyStudent);


    }

}
